package com.gcb.controller.system;

import com.gcb.common.annotation.Log;
import com.gcb.common.utils.poi.ExcelUtil;
import com.gcb.controller.BaseController;
import com.gcb.common.core.domain.AjaxResult;
import com.gcb.common.core.page.TableDataInfo;
import com.gcb.common.enums.BusinessType;
import com.gcb.domain.entity.SysVersion;
import com.gcb.service.ISysVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 项目版本Controller
 *
 * @author seh
 * @date 2023-12-27
 */
@RestController
@RequestMapping("/system/version")
public class SysVersionController extends BaseController {
    @Autowired
    private ISysVersionService sysVersionService;

    /**
     * 查询项目版本列表
     */
    @PreAuthorize("@ss.hasPermi('system:version:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysVersion sysVersion) {
        startPage();
        List<SysVersion> list = sysVersionService.selectSysVersionList(sysVersion);
        return getDataTable(list);
    }

    /**
     * 导出项目版本列表
     */
    @PreAuthorize("@ss.hasPermi('system:version:export')")
    @Log(title = "项目版本", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysVersion sysVersion) {
        List<SysVersion> list = sysVersionService.selectSysVersionList(sysVersion);
        ExcelUtil<SysVersion> util = new ExcelUtil<SysVersion>(SysVersion.class);
        util.exportExcel(response, list, "项目版本数据");
    }

    /**
     * 获取项目版本详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:version:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sysVersionService.selectSysVersionById(id));
    }

    /**
     * 新增项目版本
     */
    @PreAuthorize("@ss.hasPermi('system:version:add')")
    @Log(title = "项目版本", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysVersion sysVersion) {
        return toAjax(sysVersionService.insertSysVersion(sysVersion));
    }

    /**
     * 修改项目版本
     */
    @PreAuthorize("@ss.hasPermi('system:version:edit')")
    @Log(title = "项目版本", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysVersion sysVersion) {
        return toAjax(sysVersionService.updateSysVersion(sysVersion));
    }

    /**
     * 删除项目版本
     */
    @PreAuthorize("@ss.hasPermi('system:version:remove')")
    @Log(title = "项目版本", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysVersionService.deleteSysVersionByIds(ids));
    }
}
